<template>
  <div>
    <creat v-if="showcreat" @close="showcreat = false" :detailId="detailId" :type="type" @success="refreshList(pageNo)"></creat>
    <upgrade v-else-if="showupgrade" :detailId="detailId" @close="showupgrade = false" @success="refreshList(pageNo)"></upgrade>
    <check v-else-if="showcheck" @close="showcheck = false"></check>
    <show v-else-if="show" @close="show = false" :detailId="detailId"></show>
    <div v-else>
      <basic-container>
        <div class="flex_row" style="align-items: flex-start">
          <el-button size="small" type="success" @click="creatNew()" v-if="permission.jlwj_create">创建</el-button>
          <el-form inline size="small" class="ml30" ref="form" :model="form" @keyup.enter.native="refreshList()">
            <el-form-item label="文件编号:"><el-input clearable placeholder="请输入" class="w160" v-model="form.fileNumber"></el-input></el-form-item>
            <el-form-item label="文件名称:"><el-input clearable placeholder="请输入" class="w160" v-model="form.name"></el-input></el-form-item>
            <el-form-item label="文件版本号:"><el-input clearable placeholder="请输入" class="w160" v-model="form.versionNumber"></el-input></el-form-item>
            <block style="margin-top: 0px" v-if="showmore">
              <el-form-item label="控制状态:">
                <el-select v-model="form.controlStatus" clearable class="w160">
                  <el-option label="受控" value="0"></el-option>
                  <el-option label="非受控" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="内部/外来文件:">
                <el-select v-model="form.fileSource" clearable class="w160">
                  <el-option label="内部文件" :value="0"></el-option>
                  <el-option label="外来文件" :value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="编制部门:">
                <el-cascader
                  class="w160"
                  placeholder="请选择"
                  ref="newdept"
                  :options="deptOption"
                  v-model="form.createDept"
                  :show-all-levels="false"
                  clearable
                  :props="{
                    value: 'id',
                    label: 'deptName',
                    emitPath: false,
                    checkStrictly: true,
                  }"
                  filterable
                  @change="getMemberOption"
                ></el-cascader>
              </el-form-item>
              <el-form-item label="编制人:">
                <el-select placeholder="请选择" v-model="form.createUser" clearable filterable class="w160">
                  <el-option v-for="(item, i) in userList" :key="i" :value="item.id" :label="item.name"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="提交日期:">
                <el-date-picker class="w140" clearable v-model="form.beginSubmitDate" type="date" placeholder="开始日期" value-format="yyyy-MM-dd"></el-date-picker>
                -
                <el-date-picker class="w140" clearable v-model="form.endSubmitDate" type="date" value-format="yyyy-MM-dd" placeholder="结束日期"></el-date-picker>
              </el-form-item>
              <el-form-item label="批准日期:">
                <el-date-picker class="w140" clearable v-model="form.beginApproveDate" type="date" placeholder="开始日期" value-format="yyyy-MM-dd"></el-date-picker>
                -
                <el-date-picker class="w140" clearable v-model="form.endApproveDate" type="date" value-format="yyyy-MM-dd" placeholder="结束日期"></el-date-picker>
              </el-form-item>
              <el-form-item label="生效日期:">
                <el-date-picker class="w140" clearable v-model="form.beginShengxiaoDate" type="date" placeholder="开始日期" value-format="yyyy-MM-dd"></el-date-picker>
                -
                <el-date-picker class="w140" clearable v-model="form.endShengxiaoDate" type="date" value-format="yyyy-MM-dd" placeholder="结束日期"></el-date-picker>
              </el-form-item>
            </block>
            <el-form-item style="margin-right: 0">
              <el-button type="primary" @click="refreshList(1)">查询</el-button>
              <el-button type="default" plain @click="resetSearch">重置</el-button>
              <el-button type="primary" plain @click="showmore = !showmore">
                更多筛选条件
                <i :class="{ 'el-icon-arrow-down': !showmore, 'el-icon-arrow-up': showmore }"></i>
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </basic-container>
      <basic-container>
        <el-table ref="table" :data="tableData" :height="$height - 290 + 'px'" v-loading="loading">
          <el-table-column type="index" width="50" label="序号"></el-table-column>
          <el-table-column prop="fileNumber" label="文件编号" :width="getAdaptionWidth('fileNumber', tableData)"></el-table-column>
          <el-table-column prop="name" label="文件名称" :width="getAdaptionWidth('name', tableData)"></el-table-column>
          <el-table-column prop="versionNumber" label="文件版本号" width="100"></el-table-column>
          <el-table-column label="控制状态">
            <template slot-scope="scope">
              {{ scope.row.controlStatus == '0' ? '受控' : '非受控' }}
            </template>
          </el-table-column>
          <el-table-column label="内部/外来文件" width="120">
            <template slot-scope="scope">
              {{ scope.row.fileSource == '0' ? '内部文件' : '外来文件' }}
            </template>
          </el-table-column>
          <el-table-column prop="pageCount" label="页码数量"></el-table-column>
          <el-table-column prop="createDeptName" label="编制部门" :width="getAdaptionWidth('createDeptName', tableData)"></el-table-column>
          <el-table-column prop="createUserName" label="编制人" show-overflow-tooltip></el-table-column>
          <el-table-column label="提交时间" prop="createTime" width="160"></el-table-column>
          <el-table-column label="批准日期" width="100">
            <template slot-scope="scope">
              {{ scope.row.approveDate.substr(0, 10) || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="生效日期" width="100">
            <template slot-scope="scope">
              {{ scope.row.beginTime.substr(0, 10) || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="工作流状态" fixed="right" width="100">
            <template slot-scope="scope">
              <span :class="processStatusList[scope.row.processStatus].class">
                {{ scope.row.processStatus >= 0 ? processStatusList[scope.row.processStatus].text : '-' }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="现行/作废状态" fixed="right" width="120">
            <template slot-scope="scope">
              <span>{{ scope.row.invalidStatus >= 0 ? invalidStatusList[scope.row.invalidStatus] : '-' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" width="180">
            <template slot-scope="scope">
              <el-tooltip effect="dark" content="文件已加密" placement="top-start" v-if="scope.row.isEncryption == 1 && permission.jlwj_show">
                <span class="pointer f14 nosee_f">查看</span>
              </el-tooltip>
              <span class="pointer main_co f14" v-if="scope.row.isEncryption != 1 && permission.jlwj_show" @click="handleShow(scope.row)">查看</span>
              <span class="pointer main_co f14 ml30" @click="applyShow(scope.row, 'file')" v-if="scope.row.isEncryption == 1">解密</span>
              <span class="pointer main_co f14 ml30" v-if="userInfo.user_id == scope.row.createUser && ((permission.jlwj_create && scope.row.isUpgrade == '0') || (permission.jlwj_update && scope.row.isUpgrade == '1')) && (scope.row.processStatus == 4 || scope.row.processStatus == 5 || scope.row.processStatus == 6)" @click="creatNew(scope.row, 1)"> 修改 </span>
              <el-tooltip effect="dark" content="文件已加密" placement="top-start" v-if="userInfo.user_id == scope.row.createUser && scope.row.isEncryption == 1 && permission.jlwj_update && scope.row.invalidStatus == '0' && scope.row.processStatus != 4 && scope.row.processStatus != 5 && scope.row.processStatus != 6">
                <span class="pointer f14 ml30 nosee_f">升版</span>
              </el-tooltip>
              <span class="pointer success_f f14 ml30" v-if="userInfo.user_id == scope.row.createUser && scope.row.isEncryption != 1 && permission.jlwj_update && scope.row.invalidStatus == '0' && scope.row.processStatus != 4 && scope.row.processStatus != 5 && scope.row.processStatus != 6" @click="handleUpdate(scope.row)"> 升版 </span>
              <span class="pointer red_f f14 ml30" v-if="permission.jlwj_del && scope.row.invalidStatus == 1 && scope.row.isShowDel == 1 && userInfo.user_id == scope.row.createUser" @click="confirmDel(scope.row)"> 删除 </span>
              <span class="pointer red_f f14 ml30" v-if="permission.jlwj_cancel && scope.row.invalidStatus == 1 && scope.row.isShowDel != 1 && userInfo.user_id == scope.row.createUser" @click="toDel(scope.row)"> 作废 </span>
            </template>
          </el-table-column>
          <empty slot="empty" type="success"></empty>
        </el-table>
        <el-card class="pub_right">
          <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageNo" :page-size="pageSize" :total="total" background layout="total, prev, pager, next, jumper"></el-pagination>
        </el-card>
      </basic-container>
    </div>
    <encryption :list="rowFileList" ref="encryption"></encryption>
  </div>
</template>

<script>
import { getguifanList } from '@/api/myapi/tixiwenjian'
import creat from './creat.vue'
import upgrade from './upgrade.vue'
import check from './check.vue'
import show from './show.vue'
export default {
  components: {
    creat,
    check,
    show,
    upgrade,
  },
  data() {
    return {
      tableData: [],
      detailId: '',
      showcreat: false,
      showupgrade: false,
      showcheck: false,
      showmore: false,
      show: false,
      pageNo: 1,
      pageSize: 10,
      total: 0,
      type: 0,
      loading: true,
      system: 'systemjilufilesprocess',
      memberOption: [],
      form: {},
    }
  },
  created() {
    this.refreshList(1)
    this.getdeptlist()
    this.getAlluser()
  },
  beforeUpdate() {
    this.$nextTick(() => {
      if (this.$refs.table) this.$refs.table.doLayout()
    })
  },
  methods: {
    // 新建文件
    creatNew(row) {
      if (row && row.isUpgrade == '1') {
        this.detailId = row.id
        this.showupgrade = true
        return
      }
      if (row) {
        this.detailId = row.id
        this.type = 1
      } else {
        this.detailId = ''
        this.type = 0
      }
      this.showcreat = true
    },
    //升版
    handleUpdate(row) {
      this.detailId = row.id
      this.showupgrade = true
    },
    // 获取数据列表
    refreshList(pageNo) {
      this.showcreat = false
      this.showupgrade = false
      this.loading = true
      this.pageNo = pageNo
      getguifanList(
        {
          current: pageNo,
          size: this.pageSize,
          descs: 'create_time',
          ...this.form,
        },
        this.system
      ).then(({ data }) => {
        if (data && data.success) {
          this.tableData = data.data.records
          this.total = data.data.total
          setTimeout(() => {
            this.loading = false
          }, 300)
        }
      })
    },
    resetSearch() {
      this.form = {}
      this.pageNo = 1
      this.refreshList(this.pageNo)
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNo = val
      this.refreshList(val)
    },
  },
}
</script>

<style scoped="scoped">
::v-deep .el-form-item--mini.el-form-item,
.el-form-item--small.el-form-item {
  margin-bottom: 10px;
}
.searchCol {
  width: calc(100% - 300px);
}
</style>
